Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

[proposal] Add class definition style #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vpetkar
Copy link

@vpetkar vpetkar commented Dec 13, 2019

This PR will allow consumers to use a class definition style for defining experiments, instead of the existing .define method.

Working Example:

# frozen_string_literal: true
class SampleExperiment < Verdict::ExperimentDefinition
  qualify do
    true
  end

  groups do
    group :test, :half do
      description 'Test group'
    end

    group :control, :half do
      description 'Not in the experiment'
    end
  end
end

Advantages

  • Each experiment is unique by default, and those Ruby constants can be accessed directly
  • Compatible with autoload (e.g. all classes in app/experiment will be automatically loaded)
  • Accessors are simpler. Instead of using the repository and doing something like Verdict[:sample_experiment].switch(), a more natural and ergonomic method of calling SampleExperiment.switch() can be used

The code requires cleanup, along with tests and README updates. The existing .define method is unchanged.

I am looking for feedback before making this rollout ready 👍

@vpetkar vpetkar force-pushed the vpetkar/fix-autoload branch from b9de0fd to 57885d4 Compare December 13, 2019 20:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants